package com.qys.livesMall.shop.controller.app;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.shop.modal.dto.ShopReturnDTO;
import com.qys.livesMall.shop.modal.entity.*;
import com.qys.livesMall.shop.modal.query.RequestData;
import com.qys.livesMall.shop.service.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
/**
 * app-采购退货
 * @author gmx
 * @since 2023-06-08
 */
@Tag(name = "退货", description = "退货")
@RestController
@RequestMapping("/app/shopReturnPurchase")
public class AppShopReturnPurchaseController {
    @Resource
    private ShopReturnPurchaseService shopReturnPurchaseService;

    /**
     * 申请退货
     * @param shopReturnDTO
     * @return
     */
    @Operation(summary = "申请退货")
    @PostMapping("/applyFor")
    @Transactional(rollbackFor = {Exception.class})
    public R applyFor(@RequestBody ShopReturnDTO shopReturnDTO){
        return shopReturnPurchaseService.applyFor(shopReturnDTO);
    }

    @Deprecated
    @Operation(summary = "查询退货订单")
    @PostMapping("/page")
    public R<Page<ShopReturnPurchase>> page(@RequestBody RequestData<ShopReturnPurchase> data){
        LambdaQueryWrapper<ShopReturnPurchase> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.setEntity(data.getData());
        queryWrapper.orderByAsc(ShopReturnPurchase::getCreateTime);
        Page<ShopReturnPurchase> rest = shopReturnPurchaseService.page(data.getPage(), queryWrapper);
        return R.ok(rest);
    }
    @Deprecated
    @Operation(summary = "修改退货订单")
    @PostMapping("/update")
    public R update(@RequestBody ShopReturnPurchase returnPurchase){
        ShopReturnPurchase old = shopReturnPurchaseService.getById(returnPurchase.getId());
        BeanUtil.copyProperties(returnPurchase,old,CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//        shopReturnPurchaseService.updateById(old);
//        shopReturnPurchaseService.updateReturn(old);
        return null;
    }
}
